package com.it.selfAfter.utils;

import cn.hutool.jwt.JWTUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
@Data
public class JWTUtilSanss {

    @Value("${auth.jwt.key}")
    private String key;

    @Value("${auth.jwt.expire-time}")
    private Long expire;

    public String getToken(String username) {
        Map<String, Object> jwtMap = new HashMap<>();
        jwtMap.put("uid", username);
        jwtMap.put("expire_time", System.currentTimeMillis() + expire);
        return JWTUtil.createToken(jwtMap, key.getBytes());
    }

    public boolean verify(String token) {
        return JWTUtil.verify(token, key.getBytes());
    }
}
